<template>
  <el-dialog :title="`${form.typeId ? '修改' : '添加'}阶段`" :visible.sync="show" :close-on-click-modal="false" :show-close="!btnLoading" width="500px" @closed="$refs.form.resetFields()">
    <el-form ref="form" :model="form" :rules="rules" label-width="80px">
      <el-form-item prop="typeId" class="hide" />
      <el-form-item label="阶段编码" prop="typeCode"><el-input v-model.trim="form.typeCode" placeholder="请输入阶段编码" :maxlength="50" /></el-form-item>
      <el-form-item label="阶段名称" prop="typeName"><el-input v-model.trim="form.typeName" placeholder="请输入阶段名称" :maxlength="255" /></el-form-item>
      <el-form-item label="专业类别" prop="specialTypeId">
        <el-select v-model="form.specialTypeId" placeholder="请选择" default-first-option filterable style="width: 100%">
          <el-option v-for="dict in specialTypes" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="备注" prop="remark"><el-input v-model="form.remark" type="textarea" placeholder="请输入内容" :maxlength="255" /></el-form-item>
      <el-form-item label="排序" prop="seq"><el-input-number v-model="form.seq" :min="0" :max="1e8" :precision="0" controls-position="right" /></el-form-item>
      <el-form-item label="是否启用" prop="isEnable"><el-switch v-model="form.isEnable" /></el-form-item>
    </el-form>
    <div slot="footer">
      <el-button type="primary" :loading="btnLoading" @click="btnSubmit">确 定</el-button>
      <el-button :disabled="btnLoading" @click="show = false">取 消</el-button>
    </div>
  </el-dialog>
</template>
<script>
// 添加或修改阶段对话框
import { nameRule } from '@/utils/validate'
import { editFormMixin } from '@/utils/mixin'
import { getSpecialTypes } from '@/utils/dict/custom'
import { addCheckType, updateCheckType } from '@/api/qualityManage/cq'
export default {
  mixins: [editFormMixin],
  data() {
    return {
      primaryKey: 'typeId',
      addApi: addCheckType,
      updateApi: updateCheckType,
      form: {
        typeId: '',
        typeCode: '',
        typeName: '',
        specialTypeId: '',
        remark: '',
        seq: 0,
        isEnable: true
      },
      rules: {
        typeCode: [{ required: true, message: '请输入阶段编码' }, nameRule],
        typeName: [{ required: true, message: '请输入阶段名称' }, nameRule],
        specialTypeId: [{ required: true, message: '请选择专业类别' }]
      },
      specialTypes: []
    }
  },
  created() {
    getSpecialTypes().then(res => (this.specialTypes = res))
  }
}
</script>
